from sklearn.cluster import DBSCAN
from time import *
from sklearn.datasets import make_blobs
#修改了sklearn中的dbscan源码使其能够返回邻域查询和聚类的时间
if __name__ == '__main__':
    centers = [[1]*128, [-1]*128, [ -0.5]*128]
    X, labels_true = make_blobs(n_samples=100000, centers=centers, cluster_std=0.01, random_state=0)
    clustering,KD_time,Cluster_time= DBSCAN(eps=0.3,min_samples=10,n_jobs=1).fit(X) #n_job表示单核计算
    print(f"邻域节点查询时间：{KD_time}秒,聚类时间：{Cluster_time}秒")